/**
 * 
 */
package org.paybiz.util;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.paybiz.constant.PayConstant;
import org.paybiz.core.payplatform.yeePay.constant.YeepayConstant;

/**
 * 公用帮助操作
 * 
 * @author nassir wen
 * @date 2011-9-23
 * @version V2.5
 * @Company: MSD.
 * @Copyright Copyright (c) 2011
 */
public class OprateHelper {
    public static String msdKey = "";
    public static String yeepayKey = "";
    static {
        msdKey = DynamicConfig.getInstance().getValue(PayConstant.PAY_BIZ_KEY);
        yeepayKey = DynamicConfig.getInstance().getValue(YeepayConstant.KEYVALUE);
    }

    /**
     * 获取hessain来源IP
     * 
     * @return
     */
    public static String getHessainIp(HttpServletRequest request) {
        // 判断来访问的IP是否是在合法库
        String ip = request.getRemoteAddr();
        return ip;
    }

    /**
     * 获取http请求IP
     * 
     * @return
     */
    public static String getHttpIp(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
        {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
        {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
        {
            ip = request.getRemoteAddr();
        }
        return ip;
    }

   
    /**
     * 获取当前运行环境
     * 
     * @return
     */
    public static String getRunHome() {
        String runHomeStr = DynamicConfig.getInstance().getValue("run.home");
        return StringUtils.isEmpty(runHomeStr) ? "test" : runHomeStr;
    }

}
